//
//  AppDelegate.m
//  Runner
//
//  Created by 梁慧聪 on 2024/6/18.
//

#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
//#import "WatchVVLiveController.h"
//#import "LoginJPViewController.h"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions {
    
    [GeneratedPluginRegistrant registerWithRegistry:self];
    [super application:application didFinishLaunchingWithOptions:launchOptions];
    self.flutterVc = (FlutterViewController *)self.window.rootViewController;
    NSLog(@"sssss, %@",self.flutterVc);
    self.channel = [FlutterMethodChannel methodChannelWithName:@"app/invokeMethod" binaryMessenger:self.flutterVc.binaryMessenger];
    [self.channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
//        if ([call.method isEqualToString:@"showLiveVc"]) {
//            [AppDelegate.delegate showLiveVc:call.arguments];
//            result(@YES);
//        } else if ([call.method isEqualToString:@"request"]) {
//            NSString *url = call.arguments[@"url"];
//            
//            if ([url isKindOfClass:[NSString class]]) {
//                [HttpVVTools GET:url parameters:call.arguments[@"parameters"] andJsessionid:@"11" success:^(id  _Nonnull responseObject) {
//                    result([VVCommTools convertToJSONData:responseObject]);
//                } failure:^(NSError * _Nullable error) {
//                    result([FlutterError errorWithCode:@"ERROR_CODE" message:error.localizedDescription details:nil]);
//                }];
//            }
//        } else if ([call.method isEqualToString:@"exit"]) {
//            [ImVVManager.sharedImVVManager nmlogoutMyacountWithFengjing];
//            [AppDelegate.delegate setWelcomeViewController];
//            result(@YES);
//        } else {
            result(FlutterMethodNotImplemented);
//        }
    }];
    return YES;
}

+ (AppDelegate *)delegate {
    return (AppDelegate *)UIApplication.sharedApplication.delegate;
}
//+ (UITabBarController *)AppTabBarController {
//    return [self delegate].tabBarController;
//}
- (void)languageSwitchResetInterface {}

- (void)app_resetRootViewController {
    [self setWelcomeViewController];
}

- (UIViewController *)getRootViewController {
    UINavigationController *root = [[UINavigationController alloc]init];
//    root.delegate = self;
//    if ([SXUserManager isLogin] == NO) {
//        LoginJPViewController *loginVc = [[LoginJPViewController alloc]init];
//        loginVc.jp_isLiveVCPush = NO;
//        loginVc.hiddenCloseButton = YES;
//        root.viewControllers = @[self.flutterVc, loginVc];
//    } else {
        root.viewControllers = @[self.flutterVc];
//    }
    return root;
}

- (void)setWelcomeViewController {
    UIViewController *root = [self getRootViewController];
//    self.window.backgroundColor = [UIColor colorWithHexString:@"#f0f0f0"];
    self.window.rootViewController = root;
    [self.window makeKeyAndVisible];
}

- (void)showLiveVc:(NSDictionary *)model {
//    VideoVVLiveModel *item = [VideoVVLiveModel mj_objectWithKeyValues:model];
//    WatchVVLiveController *liveVc = [[WatchVVLiveController alloc]init];
//    liveVc.roomid = item.roomId;
//    liveVc.videoModel = item;
//    liveVc.enterModel = [EnterVVRoomModel mj_objectWithKeyValues:model];
//    [self.flutterVc.navigationController pushViewController:liveVc animated:YES];
}

//- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
//    if ([viewController isEqual:self.flutterVc]) {
//        navigationController.navigationBar.hidden = YES;
//    } else {
//        navigationController.navigationBar.hidden = NO;
//    }
//}
@end
